#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup(){
    
    radius1 = 100;
    circ1.set(ofRandom(radius1, ofGetWidth() - radius1),
              ofRandom(radius1, ofGetHeight() - radius1));
    
    
    vel1.set(1, 1);
    
    radius2 = 75;
    
    circ2.set(ofRandom(radius2, ofGetWidth() - radius2),
              ofRandom(radius2, ofGetHeight() - radius2));
    
    vel2.set(1, 1);
    
    color.set(255);
    
    circPtr = &circ1;
}

//--------------------------------------------------------------
void testApp::update(){
    moveCircle(&circ1, &vel1, radius1);
    moveCircle(&circ2, &vel2, radius2);
    
    color.set(255);
    
    if(myDist(circ1, circ2) <= radius1 + radius2){
        color.set(255, 0, 0);
    }
    
}

//--------------------------------------------------------------
void testApp::draw(){
    ofSetColor(color);
    
    ofCircle(circ1, radius1);
    
    ofCircle(circ2, radius2);
    
    ofSetColor(0, 255, 0);
    
    ofCircle(*circPtr, radius1/2);
}
//--------------------------------------------------------------

void testApp::moveCircle(ofPoint* circ, ofVec2f* vel, float radius){
    *circ += *vel;
    
    if((circ->x > ofGetWidth() - radius) || (circ->x < radius)){
        vel->x *= -1;
    }
    
    if((circ->y > ofGetHeight() - radius) || (circ->y < radius)){
        vel->y *= -1;
    }
}

//--------------------------------------------------------------

float testApp::myDist(ofPoint p1, ofPoint p2){
    return ofDist(p1.x, p1.y, p2.x, p2.y);
}

//--------------------------------------------------------------
void testApp::keyPressed(int key){
    if(key == 49){
        circPtr = &circ1;
    }
    if(key == 50){
        circPtr = &circ2;
    }
}

//--------------------------------------------------------------
void testApp::keyReleased(int key){

}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){ 

}